<template>
	<view class="pd mt100">
		<view class="z9 fz26">
			该组织管理员权限授权
		</view>
		<view class="mt20 pr parent">
			<view class="kjhnderty yj4 pr" :class="sd.cls" v-for="sd in sqssf" @tap="kjssf(sd)">
				<icon type="success" size="18" color="#fff" class="dsfrtyswr" />
				<view class="jjhdertt cen">
					<image :src="'../../static/img/AddViceKey/'+sd.icon" class="jhhdrettw cz" :class="sd.classname" mode="widthFix"></image>
				</view>
				<view class="cf fz26 cen">{{sd.name}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				sqssf: [{
						icon: 'kjjhfc.png',
						classname: '',
						name: '开关锁',
						cls: '',
						id:1
					},
					{
						icon: 'kjjhfd.png',
						classname: 'ab',
						name: '启动熄火',
						cls: '',
						id:2
					},
					{
						icon: 'kjjhfe.png',
						classname: 'ac',
						name: '分发副钥匙',
						cls: '',
						id:3
					},
					{
						icon: 'kjjhff.png',
						classname: 'ad',
						name: '远程控制',
						cls: '',
						id:4
					},
					{
						icon: 'kjjhfg.png',
						classname: 'ae',
						name: '实时位置',
						cls: '',
						id:5
					},
					{
						icon: 'kjjhfh.png',
						classname: 'af',
						name: '临时授权',
						cls: '',
						id:6
					}
				],
				carid:"",
				sf:""
			}
		},
		components: {},
		onLoad(options) {			
			this.carid=options.carid
			this.sf=options.id
			console.log("得到的",options.id)
		},
		methods: {
			kjssf(sd) {
				if (sd.cls) {
					sd.cls = ""
				} else {
					sd.cls = "act"
				}
				
			},
			async power(sd){
				let auth=""
				this.sqssf.map((a)=>{
					if(a.cls){
						auth+=a.id+','
					}
				})
				if (auth.length > 0) {
				    auth = auth.substr(0, auth.length - 1);
				}				
				let params={}
				params.gid=sd
				params.cid=this.carid
				params.authority=auth
				let pow=await this.post('/api/car/shared',params)
				console.log("设置的权限",pow)
				// if(pow)
				uni.showToast({
					icon:"none",
					title:'设置成功'
				})
			}
		},
		onNavigationBarButtonTap() {
				console.log("得到的",this.sf)
				var that=this
				this.sqssf.map((v)=>{
					if(v.cls){
						uni.showModal({
						    title: '提示',
						    content: '确认将此车权限共享至群组吗',
						    success: function (res) {
						        if (res.confirm) {
						            that.power(that.sf)
						            uni.navigateBack({
						            	delta:3
						            })
						        }
						    }
						});
						
					}else{
						uni.showToast({
							icon:"none",
							title:'请设置权限'
						})
					}
				})
				
		},
		mounted() {}
	}
</script>
<style scoped>

</style>
